class BillController < ApplicationController
  before_filter :require_user,       :except => [ :payable_bills_feed ]
  before_filter :fetch_bill,         :only =>   [ :delete, :show, :hide ]
  before_filter :fetch_payable_bill, :only =>   [ :open_pay, :close_pay ]

  def index
  end
  
  def add
    if params[:bill]
      @bill = Bill.new(params[:bill])
      @bill.user = current_user
    end
  end
  
  def destroy
  end

  def delete
  end
  
  def payable_bills_feed
    @rss_user = User.authenticate_hashed(params[:username], params[:password])
    @headers["Content-Type"] = "application/xml"
    @bills = @rss_user.find_unpaid_bills
    render :layout => false
  rescue
    @failure = true
    @bills = []
    render :layout => false
  end
  
  def show
  end
  
  def hide
  end
  
  def open_pay
  end
  
  def close_pay
  end
  
  def pay
    @payable_bill = PayableBill.find(params[:payable_bill][:id])
    @account = Account.find(params[:payable_bill][:account_id])
  end
  
private
  def fetch_bill
    @bill = Bill.find(params[:id])
  end
  
  def fetch_payable_bill
    @payable_bill = PayableBill.find(params[:id])
  end
end
